package graduate.wangyaqi.FillingQuestions;

import graduate.wangyaqi.ErrorCorrectionQuestions.ErrorCorrectionQuestions;
import graduate.wangyaqi.SeveralQuestions.SeveralQuestions;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.Optional;

@Service
public class FillingQuestionsService {
    @Resource
    private FillingQuestionsRepository fillingQuestionsRepository;

    //保存数据
    @Transactional
    public void save(FillingQuestions fillingQuestion) {
        fillingQuestionsRepository.save(fillingQuestion);
    }

    //删除数据
    @Transactional
    public void delete(long id) {
        fillingQuestionsRepository.deleteById(id);
    }

    //查询数据
    @Transactional
    public Iterable<FillingQuestions> getAll() {
        Iterable<FillingQuestions> fillingQuestions = fillingQuestionsRepository.findAll();
        return fillingQuestions;
    }

    @Transactional
    public Iterable<FillingQuestions> getAllByTaotiID(int id){
        Iterable<FillingQuestions> list = fillingQuestionsRepository.findAllByTaotiID(id);
        return list;
    }
    @Transactional
    public Optional<FillingQuestions> findById(Long aLong){
        return fillingQuestionsRepository.findById(aLong);
    };

    @Transactional
    public int countAllByStuIDadnAndTaotiID(Long taotaoId ){
        return fillingQuestionsRepository.countAllByTaotiID(taotaoId);
    }

    @Transactional
    public FillingQuestions getFirstByTaotiIDAndIdGreaterThan(long taotiId, long id){
        return fillingQuestionsRepository.getFirstByTaotiIDAndIdGreaterThan(taotiId,id);
    }

    @Transactional
    public FillingQuestions getFirstByTaotiIDAndIdIsLessThan(long taotiId, long id){
        return fillingQuestionsRepository.getFirstByTaotiIDAndIdLessThanOrderByIdDesc(taotiId,id);
    }
}
